<template>
  <el-row>
    <el-col :span="24">
      <el-table :header-cell-style="{ background: '#f5f5f5' }"
                :data="tableData"
                border
                height="300px"
                class="adminTable">
        <el-table-column prop="company_name"
                         align="center"
                         label="单位名称"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="adress"
                         align="center"
                         label="单位地址"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="contact_name"
                         align="center"
                         label="负责人"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="contact_phone"
                         align="center"
                         label="联系电话"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="create_date"
                         align="center"
                         label="创建时间"
                         show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="操作"
                         align="center">
          <template slot-scope="scope">
            <el-button type="text"
                       @click="appliAuth(scope.row)">
              申请授权
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-col>
  </el-row>
</template>

<script>
import { unitManageApi } from "@/services/orgainzeManage";
export default {
  props: {
    judgeOpen: Number,
    objRow: Object,
    callBack: Function
  },
  data () {
    return {
      currentPage: 1,
      pagesize: 10,
      total: 0,
      tableData: [],
    }
  },
  methods: {
    //获取单位管理列表数据(表格)
    getTableData () {
      unitManageApi
        .getUnitList({
          params: {
            user_id: this.objRow.user_id,
            is_page: 0
          }
        })
        .then(
          res => {
            this.tableData = res.data.list;
            this.total = res.data.total_count;
          },
          err => {
            console.log(err);
          }
        );
    },
    //申请授权
    appliAuth (row) {
      this.callBack(row);
    },
  },
  watch: {
    judgeOpen (n, o) {
      if (this.judgeOpen == 1) {
        this.tableData = [];
        this.getTableData();
      }
      console.log('w-judgeOpen=', n, 'objrow=', this.objRow)
    }
  },
  created () {
    if (this.judgeOpen == 1) {
      this.tableData = [];
      this.getTableData();
    }
    console.log('c-judgeOpen=', this.judgeOpen, 'objrow=', this.objRow)
  }
}
</script>

<style lang="scss" scoped>
.col_pagination {
  padding-bottom: 20px;
  text-align: center;
}
</style>